package com.alstudio.net.protocol.xmpp;

import com.alstudio.net.protocol.xmpp.data.XmppConnectionState;
import com.alstudio.net.protocol.xmpp.packact.Message;

/**
 * Interface class to implement events
 * 
 * @author Swen Kummer, Dustin Hass, Sven Jost
 * @version 2.0
 * @since 1.0
 */
public interface XmppListener {

	/**
	 * 当无法连接到XMPP服务器时，此回调将被执行
	 */
	public void onJxaConnFailed(final String msg, final String conflictSid);

	/**
	 * 当无法连接到XMPP服务器时，此回调将被执行
	 */
	public void onJxaConnFailed(final String msg);

	/**
	 * 当登陆连接服务器的状态发生变化时，此回调将被执行
	 * 
	 * @param state
	 */
	public void onJxaConnStateChange(XmppConnectionState state);

	/**
	 * 当成功登陆服务器后，此回调将被执行
	 */
	public void onJxaAuth(final String username, String passwrod,
			String giftVersion);

	/**
	 * 当出现账号验证失败时，此回调将被执行
	 * 
	 * @param 登录失败的原因
	 */
	public void onJxaAuthFailed(final String message);

	/**
	 * 当服务器响应客户端注销登录请求时，此回调将被执行。
	 * 
	 * @param result
	 *            true表示注销成功 false表示注销失败。
	 * @author Alonso Lee
	 */
	public void onJxaLogoutEvent(boolean result);

	/**
	 * 当服务器响应更改密码请求时，此回调将被执行
	 * 
	 * @param code
	 *            0 表示更改成功；404表示密码长度不符合要求；403表示还没有绑定自定义账号；402表示原密码不对
	 * @author Alonso Lee
	 */
	public void onJxaChangePasswordEvent(int code, String newPwd);

	/**
	 * @param user
	 *            更改状态的电话号码
	 * @param show
	 *            具体状态。取值范围为"online"和"offline"
	 * @param timeStamp
	 *            当show为"online"时，timeStamp为null。否则，timeStamp为离线时间
	 */
	public void onJxaStatusEvent(final String user, final String show);

	/**
	 * 当登陆成功后，在运行过程中出现异常情况时，此回调将被执行
	 * 
	 * @param code
	 * @param nameSpace
	 */
	public void onJxaErrorOccur(final String code, final String nameSpace);

	/**
	 * 接收到消息
	 * 
	 * @param msg
	 * @author Alonso Lee
	 */
	public void onJxaMessageEvent(final Message msg);

	/**
	 * 当收到消息回执时，此回调将被执行
	 * 
	 * @param from
	 * @param id
	 * @param info
	 *            消息状态
	 * @author Alonso Lee
	 */
	public void onJxaGetMessageBackEvent(final String from, final String id);


	/******************************************* 70---129行的代码因cardboxing项目用不到，暂时关闭 ********************************************************************/
	/**
	 * This event occurs when someone has removed you from his roster (o rly?)
	 * 
	 * @param jid
	 *            the jid of the remover
	 */
	// public void onContactRemoveEvent(final String jid);

	/**
	 * This event occurs for each contact in roster when the roster is queried.
	 * 
	 * @param jid
	 *            the jid of the contact
	 * @param name
	 *            the nickname of the contact
	 * @param group
	 *            the group in which the contact is saved
	 * @param subscription
	 *            the subscription status of the contact
	 */
	// public void onJxaContactEvent(final String jid, final String name, final
	// String group, final String subscription);

	// public void onJxaContactOverEvent();
	/**
	 * <p>
	 * This event occurs when a presence message comes from jabber server. This
	 * can also be your own jid. The presence can be one of the following:
	 * </p>
	 * 
	 * <ul>
	 * <li><code>blank</code>: user is online</li>
	 * <li>chat: user is free to chat</li>
	 * <li>away: user is away</li>
	 * <li>xa: user is not available (extended away).</li>
	 * <li>dnd: user is busy (do not disturb).</li>
	 * </ul>
	 * 
	 * <p>
	 * An offline user will send no status message at all.
	 * </p>
	 * 
	 * @param user
	 *            更改状态的电话号码
	 * @param show
	 *            具体状态。取值范围为"online"和"offline"
	 * @param timeStamp
	 *            当show为"online"时，timeStamp为null。否则，timeStamp为离线时间
	 */
	// public void onJxaStatusEvent(final String user, final String show, final
	// String timeStamp);

	/**
	 * This event is sent when a subscription request arrives. This means
	 * someone has allowed you to see his status.
	 * 
	 * @param jid
	 *            the jid of the one who wants to subscribe to you
	 */
	// public void onJxaSubscribeEvent(final String jid);

	/**
	 * This event is sent when a subscription remove event arrives. This means
	 * someone has taken away your right to see his status.
	 * 
	 * @param jid
	 *            the jid of the one who removes your subscription
	 */
	// public void onJxaUnsubscribeEvent(final String jid);

	/**********************************************************************************************************/

	// 关于注册的回调通知

	/**
	 * 得到服务器下发注册的信息后通过此回调通知上层
	 * 
	 * @param userName
	 *            服务器下发的对应此IMEI的用户名。只有在注册成功或者服务器有此imei信息时才会下发账号密码
	 * @param passWord
	 *            对应userName的密码
	 */
	public void onJxaRegisterEvent(final String jid, final String password,
			final String user);

	/**
	 * 当收到服务器下发的心跳包时通知上层
	 * 
	 * @param type
	 *            此条心跳包的类型。取值范围: "0" 服务器下发的S2C心跳包，程序必须响应。否则服务器将把连接断开 "1"
	 *            服务器响应本程序上传的C2S心跳包。证明当前连接正常
	 * @param id
	 *            此条心跳包的id号
	 */
	public void onJxaGetPingEvent(int type, String id, String from, String to);

};
